from tkinter import *
# 2021-06-17 09:37 by 炸天帮成员
# 包含 控件字体变换 以及 查询控件大小 ，还有 控件函数的传参

def show(VarNumber):
    if VarNumber == 1:
        print('Var1.get() = ',Var1.get())
    elif VarNumber == 2:
        print('Var2.get() = ',Var2.get())
    elif VarNumber == 3:
        print('Var3.get() = ',Var3.get())
if __name__ == "__main__":
    main_window = Tk()
    main_window.title("About Menu Button")
    main_window_size = (400,150)
    main_window.geometry(f"{main_window_size[0]}x{main_window_size[1]}")
    main_frame = Frame(main_window)
    main_frame.place(x=0,y=0,width=main_window_size[0],height=main_window_size[1])

    menu_button = Menubutton(main_frame,text = "Foods",bg="white",fg="red",activebackground="red",activeforeground="white")
    Menu1 = Menu(menu_button,tearoff = 0)
    Var1 = IntVar()
    Var2 = IntVar()
    Var3 = IntVar()
    Menu1.add_checkbutton(label = "Pizza",variable = Var1,command = lambda :show(1))# 至于menu中可以add什么，见menu章节
    Menu1.add_checkbutton(label = "Cheese",variable = Var2,command = lambda :show(2))
    Menu1.add_checkbutton(label = "Salad",variable = Var3,command = lambda :show(3))#如果想要在command中传参，则需要使用lambda
    menu_button["menu"] = Menu1
    menu_button.place(x=0,y=0)
    # 组件大小测量
    menu_button.update()
    print('menu_button geometry = ',menu_button.winfo_geometry()) 
    main_window.update()
    print('main_window geometry = ',main_window.winfo_geometry()) 

    main_window.mainloop()
    
